home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
dvtools
/
demos
/
telecomdemo
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-10
|
7KB
|
282 lines
#ifndef lint
static char SccsId[]= "@(#)main.c V1.12 3/17/95";
#endif
/*
| File name: main.c
|========================================================================
|
| Copyright (c) 1990 -- V.I. Corporation
|
|========================================================================
*/
#include "simulate.h"
#include "tlc_fundecl.h"
#ifdef WINNT
#include <windows.h>
#endif /* WINNT */
#ifdef WINNT
LOCAL INT TimeoutInterval = 25;
LOCAL HWND Hwnd;
LOCAL VOID CALLBACK TimeOutProc V_P_((HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime));
#else /* UNIX */
/* Include the X based files so we can add AppTimeOuts */
#ifdef CONST
#undef CONST
#endif
#ifndef __STDC__
#define _NO_PROTO
#endif
/* X11 include files */
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
LOCAL XtAppContext app_context;
LOCAL void UpdateProc V_P_((ADDRESS args, XtIntervalId *interval_id));
#endif /* WINNT */
/***************** Begin Function Declarations *************/
LOCAL BOOLPARAM TimeForNextStep V_P_((void));
LOCAL void DisplayWaitScreen V_P_((void));
LOCAL void UpdateDisplay V_P_((void));
/***************** End Function Declarations *************/
#define DEF_SEARCH_PATH (ADDRESS)NULL
#define DEF_DISPFORMS (ADDRESS)NULL
#ifdef WINNT
int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
#else /* Not WINNT */
int
main (argc, argv)
int argc;
char *argv[];
#endif /* WINNT */
{
OBJECT location;
CHAR *device = NULL;
/*
* See if the user specified the device name on the command line
*/
#ifdef WINNT
device = "W";
#else /* Not WINNT */
if (argc > 1)
device = argv[1];
#endif /* WINNT */
#ifdef VMS
VUoff_copyright();
#endif
(VOID) TInit (DEF_SEARCH_PATH, DEF_DISPFORMS);
/*
* Load in all views, create the two screens and start the simulation.
*/
CreateStatusScreen (device);
DisplayWaitScreen ();
CreateLogScreen ();
CreateControlScreen(device);
InitializeSimulation ();
LoadAuxStatusViews ();
StartSimulation ();
/* Reset the cursors */
(VOID) TscSetCurrentScreen (StatusScreen);
(VOID) GRset (V_ACTIVE_CURSOR, V_END_OF_LIST);
(VOID) TscSetCurrentScreen (ControlScreen);
(VOID) GRset (V_ACTIVE_CURSOR, V_END_OF_LIST);
(VOID) TscSetCurrentScreen (LogScreen);
(VOID) GRset (V_ACTIVE_CURSOR, V_END_OF_LIST);
#ifdef WINNT
/* Get the Windows based information */
(VOID) GRget (V_WIN32_WINDOW_HANDLE, &Hwnd, V_END_OF_LIST);
/* Post a timeout for dynamic updates
| The timeout procedure will update the dynamics of
| all screens which have been opened. The procedure is invoked
| whenever the specified time interval elapses. The interval is
| specified in milliseconds.
*/
SetTimer (Hwnd, (UINT)Hwnd, TimeoutInterval, (TIMERPROC)TimeOutProc);
#else /* UNIX */
/* Extract the X information so we can setup a Time-Out Proc
| for updating....
| Get the Xt Application Context information.
| Post a timeout procedure will update the dynamics of
| all screens which have been opened. The procedure is invoked
| whenever the specified time interval elapses. The interval is
| specified in milliseconds.
*/
(VOID) GRget (V_X_APPLIC_CONTEXT, &app_context, V_END_OF_LIST);
XtAppAddTimeOut (app_context, TimeoutInterval,
(XtTimerCallbackProc) UpdateProc, NULL);
#endif /* WINNT */
/*
* Loop until the quit flag is set. Handle input in each of the windows,
* check to see if it's time for the next simulation step, and if it is,
* then do the next step and update the screens.
*/
while (*Control.quit_flag == FALSE)
{
OBJECT LocationScreen;
while ((location = VOloWinEventPoll ((INT) V_NO_WAIT)))
{
LocationScreen = VOloScreen (location);
if (LocationScreen == ControlScreen)
{
(VOID) TscSetCurrentScreen (ControlScreen);
HandleControlInput (location);
}
else if (LocationScreen == StatusScreen)
{
(VOID) TscSetCurrentScreen (StatusScreen);
HandleStatusInput (location);
}
else if (LocationScreen == LogScreen)
{
(VOID) TscSetCurrentScreen (LogScreen);
HandleLogInput (location);
}
}
UpdateDisplay();
}
/*
* When we're done, destroy the screens and exit.
*/
DestroyLogScreen ();
DestroyControlScreen ();
DestroyStatusScreen ();
(VOID) TTerminate ();
S_EXIT (EXIT_OK);
return 1;
}
LOCAL VOID UpdateDisplay V_P_((void))
{
if (TimeForNextStep ())
if (*Control.pause_flag == 0)
{
UpdateStatusScreen ();
UpdateControlScreen ();
NextSimulationStep ();
}
}
/*
* TimeForNextStep -- see if it's time for the next simulation step. Use
* DataViews internal routines to first sleep for a tenth of a second,
* and then check to see if enough time has passed for the next simulation
* step.
*/
LOCAL BOOLPARAM TimeForNextStep
V_P_ ((void))
{
INT secs, tenths;
LOCAL ULONG prev_time = 0;
ULONG curr_time;
DV_BOOL ready = NO;
Mgettime (&secs, &tenths);
curr_time = (ULONG)(secs + (tenths / 10.0));
if ( curr_time - prev_time > *Control.delay_time)
{
prev_time = curr_time;
ready = YES;
}
return ready;
}
/*
* DisplayWaitScreen -- display the initial screen. Load a message view
* and display it while the rest of the views are being loaded in.
*/
LOCAL void DisplayWaitScreen
V_P_ ((void))
{
VIEW view;
DRAWPORT drawport;
/*
view = TviLoad( "top_map.v" );
*/
view = TviLoad ("wait.v");
drawport = TdpCreate (StatusScreen, view, &FullScreen, &WholeDrawing);
(VOID) TdpDraw (drawport);
(VOID) TdpDestroy (drawport);
(VOID) TviDestroy (view);
}
/*
* VUcopyright -- disable the copyright screen. This local function
* overrides the DataViews internal routine that displays the copyright.
*/
#ifndef VMS
void VUcopyright
V_P_ ((void))
{
}
#endif
#ifdef WINNT
/*ARGSUSED*/
LOCAL VOID CALLBACK
TimeOutProc (hwnd, uMsg, idEvent, dwTime)
HWND hwnd;
UINT uMsg;
UINT idEvent;
DWORD dwTime;
{
UpdateDisplay ();
}
#else /* UNIX */
/*ARGSUSED*/
LOCAL void
UpdateProc (args, interval_id)
ADDRESS args;
XtIntervalId *interval_id;
{
UpdateDisplay ();
/* Re-Post the Time-Out */
XtAppAddTimeOut (app_context, TimeoutInterval,
(XtTimerCallbackProc) UpdateProc, NULL);
}
#endif /* WINNT */